package com.forekenow.Demo9;

import com.forekenow.Demo8.Exercise.E5.UseComputer;

public class UserManager  {
    private String [] name = new String[2];
    private String [] pass = new String[2];

    public void register(String username,String password)throws CustomException{
        //查看字符串的长度
        int nameLength = username.length();
        int passLength = password.length();

        //校验用户名和密码是否为空
        if (username.equals("")||password.equals("")){
            //抛出异常
            throw new CustomException("输入的用户名和密码为null");
        }
        //判断用户名的长度
        if (nameLength<6||nameLength>14){
            throw new CustomException("用户名长度不符合规范");
        }
        //判断密码的长度
        if (passLength<6||passLength>14){
            throw new CustomException("密码长度不符合规范");
        }
        for (int i = 0; i < name.length; i++) {
            if (name[i]==null&&pass[i]==null){
                name[i] = username;
                pass[i] = password;
                System.out.println("注册成功");
                return;
            }
        }
        throw new CustomException("用户已经达到上限,无法注册");
    }

    public static void main(String[] args) {
        UserManager userManager = new UserManager();
        try {
            userManager.register("122112","21212112");
            userManager.register("放21212","97864879");
            userManager.register("放21212","97864879");
            userManager.register("放21212","97864879");

        } catch (CustomException e) {
            e.printStackTrace();
        }
        System.out.println("程序未中止");
    }
}
